<?php session_start(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php
//a session is started
$memberID=intval($_SESSION['member_id']);

if(isset($_SESSION['lang']))
    require_once "./language_files/viewNews_" . $_SESSION['lang'] . ".php";
else
    require_once "./language_files/viewNews_en.php";

require_once "functions.php";
?>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
    <head>
        <title></title>
        <meta http-equiv="X-UA-Compatible" content="IE=9" />
        <link href="style3.css" rel="stylesheet" type="text/css" />
        <link href="jquery-ui-all.css" rel="stylesheet" type="text/css" />
        <?php include 'jquery.php';?>
        <script type="text/javascript" src="jquery-accordion.js"></script>
        <script type="text/javascript" src="functions.js"></script>
        <script type="text/javascript">
            $(document).ready(function(){
                check_top();
            });
            $(function() {
                $( "#accordion" ).accordion();
            });
        </script>
    </head>
    <body>

        <h2><?php echo $lang['Last_News'];?></h2>
        <?php
//establishing a database connection

        //executing the query that gets all the conferences' long names on which has been posted
        $get_conferences=mysql_query("select DISTINCT long_name FROM o_postnews_conference p ,
            conference c INNER JOIN member_privileges m ON (c.conference_id = m.conference_id)
            WHERE  c.conference_id = p.conference_id
            AND m.member_id = $memberID
           ") or die(mysql_error());
        echo "<div id='accordion'>";
        //loop on the conferences to get each conference's news
        while($conferences=mysql_fetch_assoc($get_conferences))
        {
            // store the conference's long name in a variable
            $conference_name = formatText_safe($conferences['long_name']);
            echo "<h1><a href='#'>{$conference_name}</a></h1>";
//executing the query that gets the news posted on a specific conference
            $get_news=mysql_query("Select ann_id, ann_title , ann_text , p.conference_id, p.member_id
                FROM o_postnews_conference p , conference c
                WHERE c.conference_id = p.conference_id
                AND c.long_name = '$conference_name'
                AND p.ann_deadline > now() ") or die(mysql_error());
            //loop on the news to display them in a table
            ?>
        <div>
            <table style='width:100%;'> <tr>
                    <td style="background-color:#003366; color:white; text-align:center;"><?php echo $lang['News_title'];?></td>
                    <td style="background-color:#003366; color:white; text-align:center;"><?php echo $lang['News_text'];?></td>
                    <td style="background-color:#003366; color:white; text-align:center;"><?php echo $lang['News_delete'];?></td></tr>
            <?php
             if(mysql_num_rows($get_news) == 0) {
                 echo "<td colspan='10' style='text-align:center;'>no news in this confernece</td>";
             }
            while($news=mysql_fetch_assoc($get_news))
            {
				$title = formatText_safe($news['ann_title']);
				$text = formatText_safe($news['ann_text']);

                //Author: Aya El Mobayad
                //if the creatorid of the piece of news being printed is equivalent
                //to the memberID of the logged in user
                if($news['member_id'] == $memberID)
                {
                    //a link to delete the item is places beside it.
                    //Its action takes place in the deleteNews page

                    echo '<tr>
                   <td> <b>' . $title . '</b></td>
                <td>' . $text . '</td>
                <td><a href="deleteNews.php?ann_id=' . $news['ann_id'] . '">Delete</a></td>
                </tr>';
                    //if the user is not the one who posted the news
                }
                else
                {
                    echo "<tr><td>
               {$title}</td>
                <td> {$text}</td></tr>";
                }
            }
            echo "</table></div>";

        }
        //The connection is closed
        mysql_close();

        //End Documentation
        ?>
    </body>
</html>


